package edu.online.service.impl;

import edu.online.dao.UserDao;
import edu.online.entity.UserEntity;
import edu.online.object.UserObject;
import edu.online.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    private UserDao userDao;

    @Autowired
    public void setUserDao (UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public boolean Add(UserObject user) {

        return false;
    }

    @Override
    public List<UserObject> selectALL() {
        List<UserObject> userObjects = new ArrayList<>();
        List<UserEntity> userEntities = userDao.selectALL();
        for(UserEntity entity : userEntities){
            userObjects.add(new UserObject(entity));
        }
        return userObjects;
    }

    @Override
    public List<UserObject> selectByUserid(String userid) {
        List<UserObject> userObjects = new ArrayList<>();
        userObjects.add(
                new UserObject(userDao.selectByPrimaryKey(userid))
        );

        return userObjects;
    }
}
